package com.javacoo.xservice.base.support.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.javacoo.xkernel.spi.ExtensionLoader;
import com.javacoo.xservice.base.support.log.config.LogConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * 日志服务接口工厂
 * <li></li>
 *
 * @author: duanyong@jccfc.com
 * @since: 2021/3/16 8:56
 */
@Slf4j
@Component
@ConditionalOnBean(LogConfig.class)
public class LogServiceFactory {
    /** 日志服务配置 */
    @Autowired
    private LogConfig logConfig;

    @Bean
    public LogService createLogService() {
        log.info("初始化志服务,实现类名称:{}",logConfig.getImpl());
        LogServiceHolder.logService = ExtensionLoader.getExtensionLoader(LogService.class).getExtension(logConfig.getImpl());
        log.info("初始化志服务成功,实现类:{}",LogServiceHolder.logService);
        return LogServiceHolder.logService;
    }
}
